home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9067 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: tuegate.tue.nl!not-for-mail
  2. From: pwk@news.eb.ele.tue.nl (Pieter Kuppens)
  3. Newsgroups: comp.lang.c++,comp.lang.c
  4. Subject: Q: follow(expect,ifyes,ifno) buggy?
  5. Date: 27 Feb 1996 15:51:37 GMT
  6. Organization: Eindhoven University of Technology, Digital Information Systems Group
  7. Message-ID: <4gv9a9$nfu@tuegate.tue.nl>
  8. NNTP-Posting-Host: red.eb.ele.tue.nl
  9. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  10.  
  11. In compiler construction (with C) the following function is often used:
  12.  
  13. follow(expect,ifyes,ifno)
  14. {
  15.     int c = getchar();
  16.     if (c==expect) return ifyes;
  17.     ungetc(c,stdin);
  18.     return ifno;
  19. }
  20.  
  21. I have my doubts on this function. If calls are nested:
  22. (abbrev. LA (look ahead) instead of follow)
  23. LA('/',LA('/',COMMENT_LINE,LA('*',COMMENT,DIV)))
  24. may very well fail on the following:
  25. nested call LA is evaluated in the function call, before another
  26. function LA is completed. Look ahead at 1 position further can disturb
  27. correct evaluation of this function.
  28.  
  29. Questions:
  30. (1)    am I right in the expected problem?
  31. (2)    how can this problem be evaded
  32. (3)    is there an C++ equivalent of this function (without the problem)
  33. (4)    if tokens '/' , '//' and '/*' can be recognised, what is the
  34.     best form for the LA( , , ) function?
  35.  
  36. Regards,
  37. Pieter Kuppens --- pwk@eb.ele.tue.nl
  38. Eindhoven University of Technology --- EH 11.24 --- (+31)40-247 3394
  39. E.S.V.V. Pusphaira on WWW; http://www2.stack.urc.tue.nl/Pusphaira/
  40.